package 强化训练;

import java.util.Scanner;

public class 进制转换 {
//    public static void main(String[] args){
//        Scanner sc = new Scanner(System.in);
////        while(sc.hasNextLine()){
//            int val = sc.nextInt();
//            int N = sc.nextInt();
////             Integer.toHexString(val);
//            System.out.println(Integer.toString(val,N));
////        }
//    }
    public static void main(String[] args) {
        char[] ch = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
        StringBuilder res = new StringBuilder();
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int N = scanner.nextInt();
        int c = 1;
        if (num < 0){
            c = -1;
        }
        num = Math.abs(num);
        while (num != 0){
            res.append(ch[num % N]);
            num = num / N;
        }
        if(c == -1){
            res.append("-");
        }
        res.reverse();
        System.out.println(res);
    }
}
